<?php
namespace My\Controller;
use Utuo\BackgroundController;
class AdContentController extends  BackgroundController
{
public function _initialize() {
		$this->setControllerTitle("广告内容管理");
		$this->setActionTitle(array(
			'index' => '广告内容列表',
			'add' => '广告内容添加',
			'modify' => '修改广告内容',
			'recycle' => '回收站'
		));
		$this->setActionNav(array(
			'index',
			'add',
			'recycle'
		));
	}
	public function getLists($is_deleted){
		$condation=array(
				'a.cid'=>$this->aid,
				'a.status'=>1,
				'a.is_deleted'=>$is_deleted
		);
	
		$id=I('article_category_id');
		$id and $condation['a.article_category_id']=$id;
		$d = D("ArticleCategory");
	    $categoryOptions = $d->getOptionTree(null, $this->aid, 'id,pid,name');
		$articleCategoryOptions=$this->getOption($categoryOptions, $id, '==请选择栏目==');
		$adContent=M('AdContent a')->join('__ARTICLE_CATEGORY__ c on a.article_category_id=c.id')->where($condation)->field('a.*,c.name as categoryName')->page($this->getPage())->select();
      
		$count=M('AdContent a')->join('__ARTICLE_CATEGORY__ c on a.article_category_id=c.id')->where($condation)->count();
      
		$this->showPage($count, $this->getPageSize());
		$this->assign("articleCategoryOptions",$articleCategoryOptions);
		
		$this->assign('adContent',$adContent)->display();
	}
	public function addAction(){
		//$adPosition=M('AdPosition')->where('cid=%d and status=1 and is_deleted=0',$this->aid)->getField('tag,name');
		//$adContent['adPositionOption']=\Utuo\Form::getOption($adPosition,'','请选择广告位');
		$d = D("ArticleCategory");
		$pid = I("get.id",0,"intval");
		$categoryOptions = $d->getOptionTree(null, $this->aid, 'id,pid,name');
		$adContent["articleCategoryOptions"]=$this->getOption($categoryOptions, "$pid", '==请选择栏目==');
		$this->assign('adContent',$adContent);
		$this->display('save');
	}
	public function modifyAction($id){
		$adPosition=M('AdPosition')->where('cid=%d and status=1 and is_deleted=0',$this->aid)->getField('tag,name');
		$adContent=D('AdContent')->find($id);
		$d = D("ArticleCategory");
		$categoryOptions = $d->getOptionTree(null, $this->aid, 'id,pid,name');
		$adContent["articleCategoryOptions"]=$this->getOption($categoryOptions,$adContent['article_category_id'], '==请选择栏目==');
		//$adContent['adPositionOption']=\Utuo\Form::getOption($adPosition,$adContent['tag'],'请选择广告位');
		$this->assign("adContent",$adContent)->display('save');
	}
}